package com.hyz.login.controller;


import com.hyz.login.model.*;
import com.hyz.login.service.*;
import org.apache.ibatis.annotations.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/page")
public class ToRegisterController {

    @Autowired
    private RegisteredtypeService registeredtypeService;
    @Autowired
    private DepartmentsService departmentsService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private ReportService reportService;


    Logger logger = LoggerFactory.getLogger(ToRegisterController.class);

    @RequestMapping("/rep/toRegister")
    public String toRegister(Model model){
        model.addAttribute("reportList",reportService.findAll("",null));
        return "rep/toRegister";
    }


    @RequestMapping("/type/selreg")
    @ResponseBody
    public List<Registeredtype> registeredtype(){
        return registeredtypeService.registeredtypeAll();
    }

    @RequestMapping("/type/seldep")
    @ResponseBody
    public List<Departments> Departments(){
        logger.info("-------------------");
        return departmentsService.departmentsAll();
    }

    @RequestMapping("/reg/Registeredid")
    @ResponseBody
    public Integer registered(String registeredId){
      return registeredtypeService.registeredtypeMoney(registeredId);
    }

    @RequestMapping("/doc/selByRegIdAndDepId")
    @ResponseBody
    public List<Doctor> doctor(String departmentId, String registeredid){
        System.out.println(doctorService.doctorsAll(departmentId,registeredid));
        System.out.println(departmentId+"挂号:"+registeredid);
        return doctorService.doctorsAll(departmentId,registeredid);
    }

    @RequestMapping("/rep/getByPhoneOrCarid")
    @ResponseBody
    public Integer getByPhoneOrCarid(String phone,String carid){
        System.out.println(phone+"sfz"+carid);
        logger.info("-----------------"+phone+"-------------------"+carid);
        if(reportService.reportCarid(carid)>0){
            return 1;
        }else if(reportService.reportPhone(phone)>0){
            return 2;
        }
        return 3;
    }

    @RequestMapping("/rep/add")
    public String add(Report report){
        reportService.reportAdd(report);

        Cashier cashier = new Cashier();
        cashier.setReportId(report.getReportId());
        cashier.setDurgname("挂号费");
        cashier.setDurgnum(1);
        if (report.getReportType()==5){
            cashier.setRepiceprice(20.00);
            cashier.setRepicetotal(20.00);
        }else if (report.getReportType()==6){
            cashier.setRepiceprice(30.00);
            cashier.setRepicetotal(30.00);
        }
        cashier.setState(2);
        cashier.setFei(0);
        return "rep/toRegister";
    }

}
